#ifndef FFPLAYER_FAUDIO_H
#define FFPLAYER_FAUDIO_H

#include "FMedia.h"
#include "SLES/OpenSLES_Android.h"

extern "C" {
#include <libswresample/swresample.h>
#include <unistd.h>

// 播放音频
void *playAudio(void *);

// 音频队列回调
void bufferQueueCallback(SLAndroidSimpleBufferQueueItf buf_queue, void *);

class FAudio : public FMedia {
public:

    FAudio();

    ~FAudio();

    // 播放
    int play();

    // 停止播放
    void stop();

    // 释放资源
    void release();

    // 设置解码上下文
    void setCodecContext(AVCodecContext *codec_ctx, int stream_idx);

    // 开启播放器
    int startPlayer();

    // 音频转换上下文
    int initSwrContext();

public:
    // 音频转码上下文
    SwrContext *swrContext;

private:
    // OpenSL ES
    SLObjectItf engineObject, mixObject, playerObject;
    SLEngineItf engineItf;
    SLEnvironmentalReverbItf mixItf;
    SLPlayItf playItf;
    SLAndroidSimpleBufferQueueItf bufferQueue;
};
};


#endif //FFPLAYER_FAUDIO_H
